
var id = globalFun.GetQueryString("id");
var fwxm = sessionStorage.getItem('fwxm');
/*服务项目用户评价*/
//点击回复 弹框出现
var img = sessionStorage.getItem('da');
	$('.shangp').attr('src',img);

$('.pinglun').on('click', function() {
	$('.projectileFrame').show();
})
//点击回复 弹框消失
$(document).on('click','.pinglun', function() {
	$('.projectileFrame').show();
	
	$(".replyText").val('');
	var commentId=$(this).attr("data-id");
	var operationId=$(this).attr("data-mid");
	var objectName=$(this).attr("data-cid");
	
	$('.huifu').attr("data-id",commentId).attr("data-mid",operationId).attr("data-cid",objectName);
//	var zxContent = $(".replyText").val();
//	console.log($(".replyText").val());
//	console.log($(".replyText"));
//	if (zxContent == "" || zxContent.length == 0) {
//		tips("评论内容不能为空");
//		return false;
//	}
//	if (zxContent.length > 140) {
//		tips("评论内容不能超过140字");
//		return false;
//	}
//	$('.projectileFrame').hide();
});

//回复
$(document).on('click','.huifu', function () {
	var commentId=$(this).attr("data-id");
	var operationId=$(this).attr("data-mid");
	var objectName=$(this).attr("data-cid");
	var zxContent = $(".replyText").val();
	if (zxContent == "" || zxContent.length == 0) {
		tips("评论内容不能为空");
		return false;
	}
	if (zxContent.length > 140) {
		tips("评论内容不能超过140字");
		return false;
	}
	$('.projectileFrame').hide();
	
		
	$.ajax({
		type: "post",
		url: apicom + "mobile/after/order/ordercomment/replyComment",
		data: {
			id:user_info.id,
			commentId:commentId,
			content:zxContent,
			operationId: operationId,
			operationObjectId:commentId,
			objectName:objectName,
			uuid:user_info.uuid,
			phone:user_info.phone,
			
		},
		dataType: "json",
		success: function(res) {
			if (typeof(res) == 'string') {
				res = JSON.parse(res);
			}
			if (res.code == 1) {
//				console.log(111);
				location.reload();
			} else {
				tips(res.msg);
			}
			
		},
		error: function(err) {
			console.log(err)
		}
	});
	
});

//全部样式切换
$(".home_xq1").on("click", "span", function() {
	$(this).css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
});
//全部
$('.quanbu').click(function() {
//	$('.conent1').show();
//	$('.conent2').hide();
//	$('.conent3').hide();
//	$('.conent4').hide();
	getDataList(0, 1);
});
//好评
$('.haoping').click(function() {
//	$('.conent2').show();
//	$('.conent1').hide();
//	$('.conent3').hide();
//	$('.conent4').hide();
	getDataList(1, 1);
});
//中评
$('.zhongping').click(function() {
//	$('.conent3').show();
//	$('.conent1').hide();
//	$('.conent2').hide();
//	$('.conent4').hide();
	getDataList(2, 1);
});
//差评
$('.chaping').click(function() {
//	$('.conent4').show();
//	$('.conent1').hide();
//	$('.conent2').hide();
//	$('.conent3').hide();
	getDataList(3, 1);
});

var id = globalFun.GetQueryString("id")
//id = 2
getDataList(0, 1)
/* 获取评论列表 */

function getDataList(level, page) {
	if(!Auth()){
		var pa = {
			servcieProjectId: id,
			level: level,
			page: page,
			rows: 10
		}
		
	}else{
		var pa = {
			servcieProjectId: id,
			level: level,
			page: page,
			rows: 10,
			uuid:user_info.uuid,
			phone:user_info.phone,
			memberId:user_info.id
		}
	}
	$.ajax({
		type: "post",
		url: apicom + "mobile/view/ordercomment/getServiceOrderCommentList",
		data:pa,
		dataType: "json",
		success: function(res) {
			if (typeof(res) == 'string') {
				res = JSON.parse(res);
			}
			if (res.code == 1) {
				renderData(res.content)
			} else {
				tips(res.msg);
			}
		},
		error: function(err) {
			console.log(err)
		}
	})
}
/* 页面回显评论列表 */
function renderData(datalist) {
	var content = "";
	for (var l = 0; l < datalist.length; l++) {
		var data = datalist[l]
		content += '<div><div class="current-in"><ul><li class="current-tx">'
//		content += '<img src = "../../img/d_staryou.png" />'
		
		if(data.logo == "") {
			content += '<img src="https:yst-pjyc-server.oss-cn-beijing.aliyuncs.com/datas/image/20180611/20180611170204559233380.png"/>'
		} else {
			content += '<img src = "' + data.logo + '" />'
		}
		
		
		content += '</li> <li   class = "current-name" ><div>' + data.memberName + '</div>';
		content += '<div class="current-xj">'
		for (var i = 0; i < 5; i++) {
			if (i < data.startNum) {
				content += '<img src = "../../img/d_staryou.png" />'
			} else {
				content += '<img src = "../../img/d_starwu.png" />'
			}
		}
		content += '</div></li>'
		content += '<li class = "current-time" >';
		content += '<span class="current-time1">' + data.createdTime + '</span></li></ul>';

		content += '<div class = "current-hp" >';
		content += '<span class="current-hp1">' + data.content + '</span> </div >';


		if (data.picture) {
			content += '<div class = "current-tp" >'
			var picture = data.picture.split(",")
			for (var i = 0; i < picture.length; i++) {
				content += '<div style="background-image:url(' + picture[i] + ')"></div>'
			}
			content += '</div>'
		}
		
		for(var i = 0; i< data.returnOrderCommentVOS.length;i++){
			if(data.returnOrderCommentVOS[i].memberName){
				content += '<div class = "home_sjhf" >'
		
				content += '<span >'+data.returnOrderCommentVOS[i].memberName+' :<b>'+data.returnOrderCommentVOS[i].content +'<b></span></div>'
			}else{
				content += '<div class = "home_sjhf" >'
				content += '<img src="../../img/w_huifu.png" class="sjhf"/>'
		
				content += '<span >商家： <b>'+data.returnOrderCommentVOS[i].content +'<b></span></div>'
			}
				
		}
		
//		content += '<div class = "home_sjhf" >'
//		content += '<img src="../../img/w_huifu.png" class="sjhf"/>'
//		content += '<span >商家： 谢谢悟空 谢谢商家 </span></div>'
		content += '<div class = "active1"><span class="liulan">浏览<b>'+ data.readNum+'次</b></span><span data-id="'+data.id+'" class = "dianzan">'
		if(data.isFabulous == 0){
			content+='<img data-type="1" src="../../img/a_zan.png"/>'
		}else{
			content+='<img data-type="2" src="../../img/a_zan_1.png"/>'
		}
		content += '<b class="dianzanj">' + data.fabulousNum + '</b> </span >'
		content += '<span  data-cid="'+data.memberName+'" data-mid="'+data.memberId+'" data-id="'+data.id+'" class = "dianzan1 pinglun" >'
		content += '<img src="../../img/w_huifu.png"/><b>回复</b></span></div></div>'
	}
	$(".conent1").html(content)
}


//点赞
$(document).on('click','.dianzan',function(){
	if(Auth()) {
			uuid = user_info.uuid;
			phone = user_info.phone;
			id  = user_info.id;
		}else{
			toClientLogin()
		}
	var dianzan1 = $(this);
	var pid = $(this).attr('data-id');
	var zt = $(this).children("img").attr("data-type");
	console.log(zt)
	if(!Auth()){
		toClientLogin();
	}else{
	 	if(zt == 1){
	 		$(this).children("img").attr("data-type",2);
	 		
	 		$.ajax({
	 			type:"post",
	 			url:apicom+"mobile/after/consulationfabulous/fabulous",
	 			data:{
	 				consultationId:'',
	 				type:1,
	 				planId:'',
	 				consultationType:5,
	 				consultationCommentId:'',
	 				orderCommentId: pid,
	 				phone:user_info.phone,
	 				uuid:user_info.uuid,
	 				serviceId:id
	 			},
	 			success:function(res){
			        if(typeof res == "string"){
			            var data=JSON.parse(res);
			        }else{
			            var data=res;
			        }	
			        if(data.code == 1){
			        	tips(data.msg);
//			        	dianzan1.addClass('red');
			        	dianzan1.find('img').attr('src','../../img/a_zan_1.png');
			        	var str1 = dianzan1.find('.dianzanj').html();
			        	dianzan1.find('.dianzanj').html( str1*1 + 1);
			        	
			        }
	 			},
	 			error:function(err){
	 				tips("服务器错误!");
	 			}
	 		});
	 	}else{
	 		$(this).children("img").attr("data-type",1);
	 		$.ajax({
	 			type:"post",
	 			url:apicom+"mobile/after/consulationfabulous/fabulous",
	 			data:{
	 				consultationId:'',
	 				type:2,
	 				planId:'',
	 				consultationType:5,
	 				consultationCommentId:'',
	 				serviceId:id,
	 				orderCommentId: pid,
	 				phone:user_info.phone,
	 				uuid:user_info.uuid
	 			},
	 			success:function(res){
			        if(typeof res == "string"){
			            var data=JSON.parse(res);
			        }else{
			            var data=res;
			        }	
			        if(data.code == 1){
			        	tips("取消点赞");
//			        	dianzan1.removeClass('red');
			        	dianzan1.find('img').attr('src','../../img/a_zan.png');
			        	var str1 = dianzan1.find('.dianzanj').html();
			        	dianzan1.find('.dianzanj').html( str1*1 -1 );
			        }
	 			},
	 			error:function(err){
	 				tips("服务器错误!");
	 			}
	 		});		
	 	}	
	}

 });
 
// $.ajax({
// 	type: "post",
//	url: apicom + "mobile/view/serviceProject/getServiceProjectDetail",
//	data:{
//		serviceProjectId:id,
//		longitude:'',
//		latitude'',
//		id:id
//	},
//	dataType: "json",
//	success: function(res) {
//		if (typeof(res) == 'string') {
//				res = JSON.parse(res);
//			}
//			if (res.code == 1) {
//				renderData(res.content)
//			} else {
//				tips(res.msg);
//			}
//		},
//		error: function(err) {
//			console.log(err)
//		}
//	})
// });
//全部  中评  好评 差评 数
$.ajax({
	type:"post",
	url:apicom+"mobile/view/serviceProject/getServiceProjectDetail",
	data:{
		serviceProjectId:id,
		longitude:111,
		latitude:12,
		id:(user_info.id?user_info.id:"")
	},
	success:function(res){
        if(typeof res == "string"){
            var data=JSON.parse(res);
        }else{
            var data=res;
        }
        var xqContent='';
        if(data.code == 1){
        	
        	data=data.content;
        	fwType=data.type;
        	fwImg=data.detailImgeList[0].imageAddress;
        	endtime=data.service_end_time;
        	starttime=data.service_start_time;
        	merchant_id=data.merchant_id;
        	if(data.isFollow){
        		//1 已收藏   0 未收藏
        		isFollow = data.isFollow;
	        	if(isFollow == 0){
	      		$(".navDp-img1 img").attr("src","../../img/d_xin.png");
//					$(".navFx-img").removeClass("red");
	        	}else{
	      		$(".navDp-img1 img").attr("src","../../img/w_fenxiangtubiao.png");
//					$(".navFx-img").addClass("red");
	        	}
        	}else{
        		
        	}
        	$(".pinglunshu1").html(data.allCommentNum);
        	$(".pinglunshu2").html(data.goodCommentNum);
        	$(".pinglunshu3").html(data.secondCommentNum);
        	$(".pinglunshu4").html(data.badCommentNum);
        	
        	
        	
        }
	},
	error:function(err){
		tips("服务器错误!");
	}
});



/* 分享 */
function toAppShare(data, self) {
  if ($(self).hasClass("dis")) {
    return false
  }
  $(self).addClass("dis")
  setTimeout(function() {
    $(self).removeClass("dis")
  }, 1000)
  if (Auth()) {

  } else {
    // toClientLogin(location.href)
    // return false;
  }
//var JSONstr = JSON.stringify(data);
  if (mark === 0) {
    //var result = lase;
    window.stub.jsToClientShare(data); //用接口stub, 通过调用内部类中的方法jsMethod给java传回result。
  } else if (mark === 1) {
    //在改function 中添加原生调起js方法
    data = JSON.parse(data);
    setupWebViewJavascriptBridge(function(bridge) {
      bridge.callHandler('jsToClientShare', data, function(resp) {});
    });
  }

}
$(".navFx-img").click(function() {
 toAppShare(fwxm, this);
});

//收藏服务
$('.navDp-imga').click(function(){
	var $this=$(this);
	if(!Auth()){
		toClientLogin();
	}else{
	 	if($(this).hasClass("red")){
	 		$.ajax({
	 			type:"post",
	 			url:apicom+"mobile/after/collection/collectionServiceProject",
	 			data:{
	 				serviceProjectId:id,
	 				uuid:user_info.uuid,
	 				phone:user_info.phone,
	 				type:11,
	 				memberId:user_info.id
	 			},
	 			success:function(res){
			        if(typeof res == "string"){
			            var data=JSON.parse(res);
			        }else{
			            var data=res;
			        }	
			        if(data.code == 1){
			        	$this.removeClass("red")
			        	$this.find('img').attr('src','../../img/w_xin.png');
			        	tips("取消收藏");
			        }
	 			},
	 			error:function(err){
	 				tips("服务器错误!");
	 			}
	 		});
	 	}else{
	 		$.ajax({
	 			type:"post",
	 			url:apicom+"mobile/after/collection/collectionServiceProject",
	 			data:{
	 				serviceProjectId:id,
	 				uuid:user_info.uuid,
	 				phone:user_info.phone,
	 				type:10,
	 				memberId:user_info.id
	 			},
	 			success:function(res){
			        if(typeof res == "string"){
			            var data=JSON.parse(res);
			        }else{
			            var data=res;
			        }	
			        if(data.code == 1){
			        	$this.addClass("red")
			        	$this.attr('src','../../img/w_fenxiangtubiao.png');
			        	
			        	tips("收藏成功");
			        }
	 			},
	 			error:function(err){
	 				tips("服务器错误!");
	 			}
	 		});		
	 	}	
	}

 });
 


var level = globalFun.GetQueryString("type");
//详情页跳转详情列表对应评价类型
if(level == 0) { //全部
	$('.quanbu').css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
} else if(level == 1) { //好评
	$('.haoping').css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
} else if(level == 2) { //中评
	$('.zhongping').css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
} else if(level == 3) { //差评
	$('.chaping').css('background', '#F25C5C').siblings().css('background', 'rgba(255,235,234,1)');
}